'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const pageIndex = event.pageIndex-1;
	console.log('event : ', event)
	let res =  await db.collection("userpublish").orderBy('recordtime','desc').skip(pageIndex * 5).limit(5).get();
	let count = await db.collection("userpublish").count()
	res.data = res.data.map(item => {
	    return {
	      ...item,
	      id: item._id,
	      _id: undefined // 删除原来的_id字段
	    };
	  });
	  res.total = count;
	  return res;
};
